/**
 * 自定义hooks之-useLatest获取最新的值
 */
import { useRef, useEffect } from "react";

export const useLatest = <T>(value: T): T => {
  const ref = useRef<T>();
  ref.current = value;

  return ref.current;
};

export const usePrevious = <T>(value: T): T => {
  const ref = useRef<T>(value);

  useEffect(() => {
    ref.current = value;
  }, [value]);

  return ref.current;
};
